package cn.edu.sdu.sol.intake_system.controller;

import cn.edu.sdu.sol.intake_system.model.vo.DataRequest;
import cn.edu.sdu.sol.intake_system.model.vo.DataResponse;
import cn.edu.sdu.sol.intake_system.service.AdminService;
import cn.edu.sdu.sol.intake_system.service.PersonService;
import cn.edu.sdu.sol.intake_system.service.QuestionService;
import cn.edu.sdu.sol.intake_system.service.WillService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@CrossOrigin(origins = "*", maxAge = 3600)
@RestController
@RequestMapping("/api/user")
public class PersonController {
    @Autowired
    PersonService personService;

    @Autowired
    WillService willService;

    @Autowired
    QuestionService questionService;

    @Autowired
    AdminService adminService;

    @PostMapping("/updateInf")
    public DataResponse updateInf(@RequestBody DataRequest req, @RequestHeader("Authorization") String token) {
        return personService.update(req, token);
    }

    @PostMapping("/getPersonInf")
    public DataResponse getPersonInf(@RequestHeader("Authorization") String token) {
        return personService.getPersonInf(token);
    }

    @PostMapping("/getDepartmentInf")
    public DataResponse getDepartmentInf(@RequestBody DataRequest dataRequest,
                                         @RequestHeader("Authorization") String token) {
        return adminService.getDepartmentInf(dataRequest, token);
    }

    @PostMapping("/changeWill")
    public DataResponse changeWill(@RequestBody DataRequest dataRequest,
                                   @RequestHeader("Authorization") String token) {
        return willService.changeWill(dataRequest, token);
    }

    @PostMapping("/cancelWill")
    public DataResponse cancelWill(@RequestBody DataRequest dataRequest,
                                   @RequestHeader("Authorization") String token) {
        return willService.cancelWill(dataRequest, token);
    }

    @PostMapping("/getWills")
    public DataResponse getWills(@RequestHeader("Authorization") String token) {
        return willService.getUserWills(token);
    }

    @PostMapping("/getQuestion")
    public DataResponse getQuestion(@RequestBody DataRequest dataRequest,
                                    @RequestHeader("Authorization") String token) {
        return questionService.getQuestionByOrder(dataRequest, token);
    }

    @PostMapping("/submitAnswers")
    public DataResponse submitAnswers(@RequestBody DataRequest dataRequest,
                                      @RequestHeader("Authorization") String token) {
        return questionService.submitAnswers(dataRequest, token);
    }

    @PostMapping("/getResult")
    public DataResponse getResult(@RequestBody DataRequest dataRequest,
                                  @RequestHeader("Authorization") String token) {
        return willService.getResult(dataRequest, token);
    }
}
